package com.mo2323.merchant.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mo2323.common.VO;
import com.mo2323.common.dbo.StatPageInfo;
import com.mo2323.common.util.AjaxObject;
import com.mo2323.common.util.Page;
import com.mo2323.service.merchant.ICommentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


@Controller
@RequestMapping("/comment")
public class CommentController extends BaseController{
    @Reference
    private ICommentService commentService;

    @RequestMapping(value = "/list", method ={RequestMethod.POST, RequestMethod.GET} )
    @ResponseBody
    public AjaxObject getCommentList(@RequestParam int vid,
                                    @RequestParam(value = "page", defaultValue = "1", required = false) int page,
                                    @RequestParam(value = "rows", defaultValue = "10", required = false) int rows){
        try{
            Page pageDefine = new Page();
            pageDefine.setPage(page);
            pageDefine.setRows(rows);
            //查询评论分页数据
            StatPageInfo<Map<String, Object>> pageInfo = commentService.getCommentList(vid, pageDefine);
            //查询场馆评论基础出具
            VO commentInfo = commentService.getCommentInfo(vid);

            VO retVO = new VO();
            retVO.set("commentInfo", commentInfo.toHashMap(true));
            retVO.set("list", pageInfo.getList());
            retVO.set("total", pageInfo.getTotal());

            return AjaxObject.ok().put("data", retVO.toHashMap(true));
        } catch (Exception e){
            logger.error("getCommentList Exception：", e);
            return AjaxObject.error("getCommentList Exception：" + e.getMessage());
        }
    }
}
